//初始化数据
$(function () {
    getData(1,6);
})
//更新数据
function getData(pageNo,length) {
    $.ajax({
        url: "/mall/orderList",
        type: "POST",
        dataType: "json",
        data:getSearch(pageNo,length),
        success:function (json) {
            var str="";
            var dataList = json.data.list;
            createPageNav({
                $container : $("#pageing"),
                pageCount :json.data.pages,
                currentNum : json.data.pageNum,
                afterFun : function(num){
                    getData(num,6);
                },
                hasCommonPage:false
            });

            for (var i = 0; i < dataList.length; i++) {
                var routeType =dataList[i].routeType;
                var status = dataList[i].orderStatus;
                if (routeType ==1){routeType="省内活动订单"}
                if (routeType ==2){routeType="省外活动订单"}
                if (routeType ==3){routeType="国外活动订单"}
                if (status ==1){status="已付款"}
                if (status ==2){status="未付款"}
                var date = "";
                date = new Date(dataList[i].gmtModify);
                str += "<tr>"
                    + "<th>" + dataList[i].orderNo + "</th>"
                    + "<th>" + dataList[i].routeName + "</th>"
                    + "<th>" + routeType + "</th>"
                    + "<th>" + validate(dataList[i].realName) + "</th>"
                    + "<th>" + dataList[i].phone + "</th>"
                    + "<th>" + status + "</th>"
                    + "<th>" + formatDate(dataList[i].createTime)+ "</th>"
                    + "</tr>"
            }
            $('#list').html(str);
        },
        error:function () {
            alert("操作失败");
        }
    })
}


//获取检索条件
function getSearch(pageNo,length) {
    var orderNo = $('[name="orderNo"]').val();
    var routeType = $('[name="routeType"]').val();
    var status = $('[name="status"]').val();
    var starttime = $('[name="starttime"]').val();
    var endtime = $('[name="endtime"]').val();
    var parm={pageNo:pageNo,length:length,orderNo:orderNo,status:status,routeType:routeType,starttime:starttime,endtime:endtime};
    return parm;
}
//时间戳转系统时间格式
function formatDate(now) {
    if (now==""){return "";}
    return new Date(now).toLocaleString();
}
//null转""
 function validate(data) {
    if(data==null){
        return "";
    }
    return data;
}